package com.clstu.regexp;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 演示一个去重案例
 */
public class RegExp09 {
    public static void main(String[] args) {
        String content = "我...我要学学学....学学编程java!";
        String regStr = "\\.";
        Pattern pattern = Pattern.compile(regStr);
        Matcher matcher = pattern.matcher(content);
        content = matcher.replaceAll("");//先去掉.
        System.out.println(content);
        pattern = Pattern.compile("(.)\\1+");
        matcher = pattern.matcher(content);
        while (matcher.find()){
            System.out.println("找到:"+matcher.group(0));
        }
        System.out.println(matcher.replaceAll("$1"));//在外部反向引用用$,直接反向引用用重复的单个字符替换掉((.)\\1+)

    }
}
